<?php

use app\assets\TableAsset;
use app\models\KeyMap;
use app\models\UserConfig;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;

/**
 * @var $this yii\web\View
 * @var $userList app\models\User[]
 * @var $pagination yii\data\Pagination
 */

TableAsset::register($this);

$this->title = '用户列表';
$this->params['breadcrumbs'][] = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <a href="<?php echo Url::to(['/admin/user/user-edit']);?>" class="btn btn-success btn-sm">添加</a>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <input type="checkbox" class="ace" />
                <span class="lbl"></span>
            </label>
        </th>
        <th>用户名</th>
        <th>代理商</th>
        <th>账户</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($userList as $user) {?>
        <tr>
            <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $user->id;?>" /><span class="lbl"><?php echo $user->id;?></span></label></td>
            <td><?php echo Html::encode($user->username);?></td>
            <td><?php if (empty($user->agent_id)) {
                    echo '----';
                } else {
                    echo Html::a(Html::encode($user->agent->username), ['/admin/user/agent-view', 'id' => $user->agent_id]);
                }?></td>
            <td><?php $prepaidPostpaid = UserConfig::getConfig($user->id, 'prepaid_postpaid', '');
                echo ['' => '', 'prepaid' => '预付费', 'postpaid' => '后付费'][$prepaidPostpaid];
                echo '<br />';
                echo $user->account->money;?></td>
            <td><?php echo KeyMap::getValue('user_status', $user->status);?></td>
            <td><?php echo Yii::$app->formatter->asDatetime($user->create_time);?></td>
            <td><?php echo ManagerTableOp::widget(['items' => [
                    ['icon' => 'fa fa-info-circle', 'href' => Url::to(['/admin/user/user-view', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-default', 'tip' => '详情'],
                    ['icon' => 'fa fa-pencil', 'href' => Url::to(['/admin/user/user-edit', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '修改', 'color' => 'green'],
                    ['icon' => 'fa fa-cogs', 'href' => Url::to(['/admin/user/user-config', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '配置', 'color' => 'green'],
                    ['icon' => 'fa fa-cubes', 'href' => Url::to(['/admin/user/user-package', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-info', 'tip' => '套餐', 'color' => 'blue'],
                    ['icon' => 'fa fa-sticky-note-o', 'href' => Url::to(['/admin/user/bill-list', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-info', 'tip' => '账单', 'color' => 'blue'],
                    ['icon' => 'fa fa-pie-chart', 'href' => Url::to(['/admin/user/user-analyze', 'id' => $user->id]), 'btn_class' => 'btn btn-xs btn-default', 'tip' => '分析'],
                ]]);?></td>
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
